/*-------------------------------------------------------------------------*/
/**
  @file		interface_jostle.c
  @author	Renaud Wanschoor
  @date	july 2004
  @version	$Revision: 2.2 $
  @brief	interface between jostle and plib functions

  A few functions are used in common between different partitionners, those in
  md_io.c are a example, also pagridplot is able to use data from PAGRID, JOSTLE
  METIS and it uses interface to be able to use tool specific data
  
*/
/*--------------------------------------------------------------------------*/
#include "plib.h"

/**
 * \brief permute an array
 * \params n size of the array
 * \params arr arry to be permuted
 */
void Jostle_Perm(int n,int* arr){
  randnum(n, arr);
}
/**
 * \brief initialize the random number generator
 * \params seed random number seed
 */
void Jostle_Randini(int seed){
  ran_start(seed);
}

/** 
 * \brief return a string describing some of the options used
 *
 * The returned string must be freed
 * \param CType matching scheme
 * \param WType edge weight type during the coarsening phase
 * \param RType uncoarsening method
 * \param CSeed Coarsening seed
 * \param ISeed Initial partitioning Seed
 * \param RSeed Uncoarsening seed
 * \return string describing the tool used and some of its options
 */
char *Jostle_GetScheme(int CType,int WType,int RType,int CSeed, int ISeed, int RSeed){
  char method[256];
  char *scheme;

  strcpy(method , "Jostle");
  
  if (CSeed != -1 && CSeed != IO_SEED)
    strcat(method,"-RM");
  if (ISeed != -1 && ISeed != IO_SEED)
    strcat(method,"-RI");
  if (CSeed != -1 && RSeed != IO_SEED)
    strcat(method,"-RR");
  
  scheme = U_malloc(strlen(method)+1,char,"MD_JostleGetScheme error code 1\n");
  strcpy(scheme,method);
  return scheme;
}
/**
 * \brief translate a specific partitionner application graph into a ::PlotGraphType graph
 *
 * The returned graph must be freed using PLIBG_Free()
 * \param g application graph
 * \return ::PlotGraphType graph
 */
PlotGraphType* Jostle_TransGraph(void* g){
  GraphType* graph = g;
  PlotGraphType* pgraph;

  pgraph = PLIBG_Init();

  pgraph->nvtxs     = graph->nvtxs;
  pgraph->nedges    = graph->nedges;

  pgraph->adjidx    = graph->adjidx;
  pgraph->adjncy    = graph->adjncy;
  pgraph->vwgt      = graph->vwgt;
  pgraph->adjwgt    = graph->adjwgt;
  pgraph->adjwgtsum = graph->adjwgtsum;
  pgraph->map       = graph->map;
  pgraph->pro       = graph->pro;

  return pgraph;
}
/**
 * \brief translate a specific partitionner grid into a ::PlotGridType grid
 *
 * The return grid must be freed using PLIBN_Free()
 * \param g computational grid
 * \return ::PlotGridType grid
 */
PlotGridType* Jostle_TransGrid(void* g){
  GridType* grid = g;
  PlotGridType* pgrid;

  pgrid = PLIBN_Init();

  pgrid->npro        = grid->npro;
  pgrid->nedges      = grid->nedges;
  pgrid->ratio       = grid->ratio;
  pgrid->exec        = grid->exec;
  
  pgrid->r_from      = grid->r_from;
  pgrid->r_to        = grid->r_to;
  pgrid->r_val       = grid->r_val;

  pgrid->netcost     = grid->realnetcost;
  pgrid->proratio    = grid->proratio;
  pgrid->proportion  = grid->proportion;
  pgrid->prospeed    = grid->prospeed;
  pgrid->penalty     = grid->penalty;

  return pgrid;
}
